<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Videoadm extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 */
	public function index(){
		$this->mng_video();
	}
	
//-------------------------------------------------------------------------------------------->Gallery{
	function tambah_video($mode=""){
		if($mode=="error"){
			$pesan="Kesalahan, Field Pada Form Harus Diisi";
		}elseif($mode=="sukses"){
			$pesan="Link Video Berhasil Disimpan, <a href='".site_url('administrator/mng_video')."'>View Video</a>";
		}else{
			$pesan="";	
		}
		$data['mode']  = $mode;
		$data['pesan'] = $pesan;
		$this->load->view('admin/videoadm/admin-tambah-link-video',$data);
	}
	
	function mng_video($mode=""){
		 
		if($mode=="update"){
			$pesan="Video berhasil diperbaharui";
		}elseif($mode=="delete"){
			$pesan="Data Video berhasil dihapus";
		}else{
			$pesan="";	
		}		
			  $this->load->library('pagination');
			  $this->load->model('tbl_video');
			  $banyak = $this->tbl_video->hitung();
			  $base_url = base_url();
			  $config['base_url'] = $base_url.'paneladm/videoadm/mng_video/';
			  $config['total_rows'] = $banyak;
			  $config['per_page'] = '10'; 
			  $this->pagination->initialize($config);
			  
		$data['mode']  = $mode;
		$data['pesan'] = $pesan;
		$data['jumlah']= $banyak;
		$data['query'] = $this->tbl_video->load_admin();	
        $this->load->view('admin/videoadm/admin-mng-video', $data);
    }
	
	function edit_video($id) {
	    $this->load->model('tbl_video');
		$data['query'] = $this->tbl_video->edit($id);	
        $this->load->view('admin/videoadm/admin-edit-link-video', $data);
    }
	
	function input_link_video() {
		$judul  	= mySQL_escape_string($this->input->post('video_judul'));
		$link		= mySQL_escape_string($this->input->post('video_link'));
		$deskripsi	= mySQL_escape_string($this->input->post('video_deskripsi'));
		if(empty($judul) || empty($link) || empty($deskripsi)){
			redirect('paneladm/videoadm/tambah_video/error');
		}
		$judul =strip_tags(trim($judul));
		$link =strip_tags(trim($link));
		$deskripsi =strip_tags(trim($deskripsi));
		$tanggal =date("Y-m-d");
		$this->load->model('tbl_video');
        $this->tbl_video->add($judul,$link,$tanggal,$deskripsi);
		redirect('paneladm/videoadm/tambah_video/sukses');
    }
	
	function update_link_video() {
		$judul  	= mySQL_escape_string($this->input->post('video_judul'));
		$link		= mySQL_escape_string($this->input->post('video_link'));
		$deskripsi	= mySQL_escape_string($this->input->post('video_deskripsi'));
		$id			= mySQL_escape_string($this->input->post('id'));
		if(empty($judul) || empty($link) || empty($deskripsi)){
			redirect('paneladm/videoadm/tambah_video/error');
		}
		$judul =strip_tags(trim($judul));
		$link =strip_tags(trim($link));
		$deskripsi =strip_tags(trim($deskripsi));
		$tanggal =date("Y-m-d");
		$this->load->model('tbl_video');
        $this->tbl_video->update($id,$judul,$link,$tanggal,$deskripsi);
		redirect('paneladm/videoadm/tambah_video/sukses');
    }
	
	function multi_hapus_video(){
		if (isset($_POST['delete'])){
		$cekbok = $this->input->post('cekbok');
		if($cekbok==""){
		redirect('paneladm/videoadm/mng_video');
		}
		$jumlah = count($cekbok);
		$this->load->model('tbl_video');
		for($i=0;$i<$jumlah;$i++){
		 $this->tbl_video->delete($cekbok[$i]); 
		}
		}
		redirect('paneladm/videoadm/mng_video/delete');
	}
	
	function delete_video($id){
		$this->load->model('tbl_video');
		$this->tbl_video->delete($id); 
		redirect('paneladm/videoadm/mng_video/delete');
	}

		//-------------------------------------------------------------------------------------------->Gallery}
}
